package cn.buildoncloud.labor.workermanapplet.business.modules.controller;

import cn.buildoncloud.labor.workermanapplet.business.modules.services.DataStatisticsService;
import cn.buildoncloud.labor.workermanapplet.business.modules.services.UserService;
import cn.buildoncloud.labor.workermanapplet.common.Constant;
import cn.buildoncloud.labor.workermanapplet.common.base.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * 数据统计页
 * Description: cn.buildoncloud.labor.workermanapplet.business.modules.controller
 * Created by CuiZibo on 2018/11/5 10:05
 */
@RestController
public class DataStatisticsController {

    private Logger log = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private UserService userService;

    @Autowired
    private DataStatisticsService homePageService;

    /**
     * 总览数据统计
     * @param userId
     * @return
     */
    @RequestMapping("/homePage/index")
    public Object homePageIndex(@RequestParam("userId") String userId) {
        try {

            Map<String, Object> map = homePageService.homePageIndex(userId);
            return Result.success(Constant.API_OPERATION_SUCCESS, map);
        } catch (Exception e) {
            log.error("dataStatistics/homePageIndex: ", e);
            return Result.error(Constant.API_OPERATION_FAILED);
        }

    }

    /**
     * 项目统计
     * @param projectId
     * @return
     */
    @RequestMapping("/homePage/projectIndex")
    public Object projectIndex(@RequestParam(value = "projectId") String projectId) {
        try {

            Map<String, Object> map = homePageService.projectIndex(projectId);
            return Result.success(Constant.API_OPERATION_SUCCESS, map);
        } catch (Exception e) {
            log.error("dataStatistics/projectIndex: ", e);
            return Result.error(Constant.API_OPERATION_FAILED);
        }
    }

}
